<?php

namespace app\admin\controller;

use app\BaseController;
use think\facade\View;

class Index extends BaseController
{
    //控制器初始化方法
    public function initialize()
    {
        parent::initialize();
        View::assign('title', '管理员管理');
        $this->admin = app('app\admin\model\logic\Admin');
        $this->role = app('app\admin\model\logic\AdminRole');
    }
    public function index()
    {
        halt(2222222);
        //生成搜索框角色选项  如果已经选择过就把选中值设为选中
        $post_data=input();
        if(isset($post_data['role_id'])&&$post_data['role_id']>0){
            $rs_data=$this->role->generate_role_option($post_data['role_id']);
        }else{
            $rs_data=$this->role->generate_role_option();
        }
        if($rs_data['code']==1){
            $this->assign('role_tree', $rs_data['data']);
        }else{
            $this->assign('role_tree', '');
        }
        //获取后台列表带分页
        $rs_data=$this->admin->get_admin_list_page();
        foreach($rs_data['data']['list'] as &$ve){
            if($ve['status']==1){
                $ve['stat']='正常';
            }else{
                $ve['stat']='禁用';
            }
        }
        $this->assign('list', $rs_data['data']['list']);
        $this->assign('page',$rs_data['data']['page']);
        $this->assign('count', $rs_data['count']);
        return view();
    }

    public function hello($name = 'ThinkPHP8')
    {
        return 'hello,' . $name;
    }

    public function demo()
    {
        /*
        // 模板变量赋值
        View::assign('name','ThinkPHP');
        View::assign('email','thinkphp@qq.com');
        // 或者批量赋值
        View::assign([
            'name'  => 'ThinkPHP',
            'email' => 'thinkphp@qq.com'
        ]);
        
        // 模板输出
        return View::fetch('demo');
        */
        
        return view('demo', [
            'name'  => 'ThinkPHP',
            'email' => '3127176862@qq.com'
        ]);
       
        // return View::fetch('index/demo');
    }

}
